package czt.ocr.config;

import net.sourceforge.tess4j.Tesseract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.URL;

/**
 * @author czt
 * @version 1.0
 * @since 2025/3/26
 */
@Configuration
public class OcrConfig {
    @Bean
    public Tesseract tesseract() {

        Tesseract tesseract = new Tesseract();
        // 设置训练数据文件夹路径
        URL resourceUrl = getClass().getClassLoader().getResource("data");
        if (resourceUrl != null) {
            String dataPath = resourceUrl.getPath();
            tesseract.setDatapath(dataPath);
        }
        // 设置为中文简体
        tesseract.setLanguage("chi_sim");
        return tesseract;
    }
}
